/**
 * @author Hari K J
 */
package com.oolatina.fragments;

import java.util.ArrayList;
import java.util.HashMap;

import com.oolatina.R;
import com.oolatina.activity.MainActivity;
import com.oolatina.modal.Consts;

import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.View.OnKeyListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.CycleInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * @author Hari K J
 * 
 */
public class LeftMenuFragment extends Fragment implements OnClickListener {

	private View mView;

	private View leftmenuListviewholder;
	private ArrayList<LeftMenuButtonItem> itemList;

	protected int currentPosition;

	private LinearLayout btnHolder;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
	 * android.view.ViewGroup, android.os.Bundle)
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.fragment_left_menu, null);
		
		leftmenuListviewholder = (View) mView
				.findViewById(R.id.leftmenu_listviewholder);
	
		
		
		btnHolder = (LinearLayout) mView
				.findViewById(com.oolatina.R.id.leftmenu_listlayout);
		
		LeftMenuButtonItem newsrow = new LeftMenuButtonItem(getString(R.string.leftmenu_news),R.drawable.news_icon, R.drawable.news_icon);
		addToLayout(inflater, btnHolder, newsrow, 0);
		
		LeftMenuButtonItem agenda = new LeftMenuButtonItem(getString(R.string.leftmenu_agenda),R.drawable.agenda_icon, R.drawable.agenda_icon);
		addToLayout(inflater, btnHolder, agenda, 1);
		
		LeftMenuButtonItem audio = new LeftMenuButtonItem(getString(R.string.leftmenu_audio),R.drawable.audio_icon, R.drawable.audio_icon);
		addToLayout(inflater, btnHolder, audio, 2);
		
		LeftMenuButtonItem video = new LeftMenuButtonItem(getString(R.string.leftmenu_video),R.drawable.video_icon, R.drawable.video_icon);
		addToLayout(inflater, btnHolder, video, 3);
		
		LeftMenuButtonItem radio = new LeftMenuButtonItem(getString(R.string.leftmenu_radio),R.drawable.radio_icon, R.drawable.radio_icon);
		addToLayout(inflater, btnHolder, radio, 4);
		
		return mView;
	}

	/**
	 *  of type 
	 * @since Jan 15, 2014
	 * @author BalaKJ 
	 * @param inflater 
	 * @param itemInfo 
	 * @param tag 
	 */
	private void addToLayout(LayoutInflater inflater, LinearLayout btnHolder, LeftMenuButtonItem itemInfo, int tag) {
		View btn = inflater.inflate(R.layout.leftmenu_buttonlayout, null);
		

		// if(i==itemList.size()-1)
		// btn.setBackgroundResource(R.drawable.leftmenu_logoutbtn_bg);

		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		params.setMargins(0,1 * Consts.dip, 0, 0);
		btn.setLayoutParams(params);
		ImageView icon = (ImageView) btn
				.findViewById(R.id.leftmenu_btn_icon);
		if (itemInfo.iconNormal != -1) {
			icon.setVisibility(View.VISIBLE);
			icon.setImageResource(itemInfo.iconNormal);
		} else
			icon.setVisibility(View.GONE);
		TextView title = (TextView) btn
				.findViewById(R.id.leftmenu_btn_label);
		title.setText(itemInfo.label);
		btn.setTag(tag);
		btn.setOnClickListener(this);
		btnHolder.addView(btn);
		
	}


	public class LeftMenuButtonItem {
		public String label;
		public int iconNormal;
		public int iconHighlighted;
		public boolean blankView = false;
		private String storeUrl="";

		public LeftMenuButtonItem(String label, int iconNormal,
				int iconHighlighted, String storeUrl) {
			this.label = label;
			this.iconNormal = iconNormal;
			this.iconHighlighted = iconHighlighted;
			this.storeUrl = storeUrl;
		}

		public LeftMenuButtonItem(String label, int iconNormal,
				int iconHighlighted) {
			this.label = label;
			this.iconNormal = iconNormal;
			this.iconHighlighted = iconHighlighted;
		}

	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
//		if (!((BaseSlidingACBActivity) getActivity()).isSlidingMenuOpen())
//			return;
		
		

		int position = (Integer) v.getTag();
		
		((MainActivity)getActivity()).onLeftMenuClicked(position);

	}
	
}
